<?php
# 文件名称:mail_helper.php
# MetInfo在线反馈系统 
# Copyright (C) 长沙米拓信息技术有限公司 (http://www.metinfo.cn). All rights reserved.
defined( '_SYS' ) or die( 'No direct script access allowed' );
include('mail/class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
if ( ! function_exists('sendEmail'))
{
	function sendEmail($data)
	{
		$SYS = &get_instance();
		$mail             = new PHPMailer();
		//$mail->SMTPDebug  = 3;
		
		$mail->CharSet    = "UTF-8"; // charset
		$mail->Encoding   = "base64";
		
		$mail->IsSMTP(); // telling the class to use SMTP
		//邮件系统配置
		$mail->SMTPAuth   = true;
		$mail->Host       = $SYS->config->item('smtphost'); // SMTP server
		$mail->Username   = $SYS->config->item('smtpuser'); // SMTP account username
		$mail->Password   = $SYS->config->item('smtppass');        // SMTP account password
		$mail->From       = $SYS->config->item('smtpuser');//必填，发件人Email 
		$mail->FromName   = $SYS->config->item('fromname'); //必填，发件人昵称或姓名 
		//回复
		if(isset($data['replyto']))
		{
			$name = isset($data['replyto']['name'])?$data['replyto']['name']:$data['replyto']['address'];
			$mail->AddReplyTo($data['replyto']['address'], $name);
		}
		$mail->WordWrap   = 50; // 自动换行的字数
		
		//主题
		$mail->Subject		= (isset($data['subject'])) ? $data['subject'] : '';//必填，邮件标题（主题）
		
		//$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // 可选，纯文本形势下用户看到的内容
		//邮件主体
		$body			  = (isset($data['body'])) ? $data['body'] : '';
		$body             = eregi_replace("[\]",'',$body);
		$mail->MsgHTML($body);
		
		//发送地址
		if(isset($data['toaddress']))
		{
			$address = explode("|",$data['toaddress']);
			foreach($address AS $key => $val)
			{
				$mail->AddAddress($val, "");
			}
		}
		//发送附件
		if(isset($data['attach']))
		{
			$attach = explode("|",$data['attach']);
			foreach($attach AS $key => $val)
			{
				$mail->AddAttachment($val,"");             // 附件
			}			
		}
		if(!$mail->Send()) {
		  //echo "Mailer Error: " . $mail->ErrorInfo;
		} else {
		  //echo "Message sent!";
		}
	}
}
# 本程序是一个开源系统,使用时请你仔细阅读使用协议,商业用途请自觉购买商业授权.
# Copyright (C) 长沙米拓信息技术有限公司 (http://www.metinfo.cn). All rights reserved.
?